﻿using RpcCacheClient.Config;
using RpcCacheClient.Interface;
using RpcClient.Interface;
using RpcModel;

namespace RpcCacheModular.Config
{
    internal class RpcCacheConfig : IRpcCacheConfig
    {
        private ISysConfig _Config;
        public RpcCacheConfig(ISysConfig config)
        {
            _Config = config;
        }
        /// <summary>
        /// 缓存类型
        /// </summary>
        public CacheType CacheType => _Config.GetConfigVal("rpc:CacheType", CacheType.Local);
        public CacheConfig Cache => _GetConfig();

     
        private CacheConfig _GetConfig()
        {
            MsgSource source = RpcClient.RpcClient.CurrentSource;
            CacheConfig config = new CacheConfig
            {
                SysKey = string.Join("_", source.RpcMerId, source.SystemTypeId),
                Memcached = _Config.GetConfigVal<MemcachedConfig>("cache:Memcached"),
                Redis = _Config.GetConfigVal<RedisConfig>("cache:Redis"),
            };
            return config;
        }
    }
}
